class Solution:
    def maxSubArray(self, nums: list[int]) -> int:
        now_sum = 0
        start_index = 0
        result = -float('inf')
        for index,val in enumerate(nums):
            now_sum += nums[index]
            if now_sum < 0:
                start_index = index
                now_sum = nums[index]
            result = max(result,now_sum)
        return result


s = Solution()
result = s.maxSubArray([-2,1,-3,4,-1,2,1,-5,4])
print(result)